<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Global Objects Node.js v6.2.0 Manual &amp; Documentation</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://nodejs.org/api/globals.html">
</head>
<body class="alt apidoc" id="api-section-globals">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="Go back to the home page">
          Node.js
        </a>
      </div>
      <ul>
<li><a class="nav-documentation" href="documentation.html">About these Docs</a></li>
<li><a class="nav-synopsis" href="synopsis.html">Usage &amp; Example</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-assert" href="assert.html">Assertion Testing</a></li>
<li><a class="nav-buffer" href="buffer.html">Buffer</a></li>
<li><a class="nav-addons" href="addons.html">C/C++ Addons</a></li>
<li><a class="nav-child_process" href="child_process.html">Child Processes</a></li>
<li><a class="nav-cluster" href="cluster.html">Cluster</a></li>
<li><a class="nav-cli" href="cli.html">Command Line Options</a></li>
<li><a class="nav-console" href="console.html">Console</a></li>
<li><a class="nav-crypto" href="crypto.html">Crypto</a></li>
<li><a class="nav-debugger" href="debugger.html">Debugger</a></li>
<li><a class="nav-dns" href="dns.html">DNS</a></li>
<li><a class="nav-domain" href="domain.html">Domain</a></li>
<li><a class="nav-errors" href="errors.html">Errors</a></li>
<li><a class="nav-events" href="events.html">Events</a></li>
<li><a class="nav-fs" href="fs.html">File System</a></li>
<li><a class="nav-globals active" href="globals.html">Globals</a></li>
<li><a class="nav-http" href="http.html">HTTP</a></li>
<li><a class="nav-https" href="https.html">HTTPS</a></li>
<li><a class="nav-modules" href="modules.html">Modules</a></li>
<li><a class="nav-net" href="net.html">Net</a></li>
<li><a class="nav-os" href="os.html">OS</a></li>
<li><a class="nav-path" href="path.html">Path</a></li>
<li><a class="nav-process" href="process.html">Process</a></li>
<li><a class="nav-punycode" href="punycode.html">Punycode</a></li>
<li><a class="nav-querystring" href="querystring.html">Query Strings</a></li>
<li><a class="nav-readline" href="readline.html">Readline</a></li>
<li><a class="nav-repl" href="repl.html">REPL</a></li>
<li><a class="nav-stream" href="stream.html">Stream</a></li>
<li><a class="nav-string_decoder" href="string_decoder.html">String Decoder</a></li>
<li><a class="nav-timers" href="timers.html">Timers</a></li>
<li><a class="nav-tls" href="tls.html">TLS/SSL</a></li>
<li><a class="nav-tty" href="tty.html">TTY</a></li>
<li><a class="nav-dgram" href="dgram.html">UDP/Datagram</a></li>
<li><a class="nav-url" href="url.html">URL</a></li>
<li><a class="nav-util" href="util.html">Utilities</a></li>
<li><a class="nav-v8" href="v8.html">V8</a></li>
<li><a class="nav-vm" href="vm.html">VM</a></li>
<li><a class="nav-zlib" href="zlib.html">ZLIB</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-https-github-com-nodejs-node" href="https://github.com/nodejs/node">GitHub Repo &amp; Issue Tracker</a></li>
<li><a class="nav-http-groups-google-com-group-nodejs" href="http://groups.google.com/group/nodejs">Mailing List</a></li>
</ul>

    </div>

    <div id="column1" data-id="globals" class="interior">
      <header>
        <h1>Node.js v6.2.0 Documentation</h1>
        <div id="gtoc">
          <p>
            <a href="index.html" name="toc">Index</a> |
            <a href="all.html">View on single page</a> |
            <a href="globals.json">View as JSON</a>
          </p>
        </div>
        <hr>
      </header>

      <div id="toc">
        <h2>Table of Contents</h2>
        <ul>
<li><a href="#globals_global_objects">Global Objects</a><ul>
<li><a href="#globals_class_buffer">Class: Buffer</a></li>
<li><a href="#globals_dirname">__dirname</a></li>
<li><a href="#globals_filename">__filename</a></li>
<li><a href="#globals_clearimmediate_immediateobject">clearImmediate(immediateObject)</a></li>
<li><a href="#globals_clearinterval_intervalobject">clearInterval(intervalObject)</a></li>
<li><a href="#globals_cleartimeout_timeoutobject">clearTimeout(timeoutObject)</a></li>
<li><a href="#globals_console">console</a></li>
<li><a href="#globals_exports">exports</a></li>
<li><a href="#globals_global">global</a></li>
<li><a href="#globals_module">module</a></li>
<li><a href="#globals_process">process</a></li>
<li><a href="#globals_require">require()</a><ul>
<li><a href="#globals_require_cache">require.cache</a></li>
<li><a href="#globals_require_extensions">require.extensions</a></li>
<li><a href="#globals_require_resolve">require.resolve()</a></li>
</ul>
</li>
<li><a href="#globals_setimmediate_callback_arg">setImmediate(callback[, arg][, ...])</a></li>
<li><a href="#globals_setinterval_callback_delay_arg">setInterval(callback, delay[, arg][, ...])</a></li>
<li><a href="#globals_settimeout_callback_delay_arg">setTimeout(callback, delay[, arg][, ...])</a></li>
</ul>
</li>
</ul>

      </div>

      <div id="apicontent">
        <h1>Global Objects<span><a class="mark" href="#globals_global_objects" id="globals_global_objects">#</a></span></h1>
<!-- type=misc -->
<p>These objects are available in all modules. Some of these objects aren&#39;t
actually in the global scope but in the module scope - this will be noted.</p>
<h2>Class: Buffer<span><a class="mark" href="#globals_class_buffer" id="globals_class_buffer">#</a></span></h2>
<!-- type=global -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>Used to handle binary data. See the <a href="buffer.html">buffer section</a>.</p>
<h2>__dirname<span><a class="mark" href="#globals_dirname" id="globals_dirname">#</a></span></h2>
<!-- type=var -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a></li>
</ul>
<p>The name of the directory that the currently executing script resides in.</p>
<p>Example: running <code>node example.js</code> from <code>/Users/mjr</code></p>
<pre><code class="lang-js">console.log(__dirname);
// /Users/mjr
</code></pre>
<p><code>__dirname</code> isn&#39;t actually a global but rather local to each module.</p>
<p>For instance, given two modules: <code>a</code> and <code>b</code>, where <code>b</code> is a dependency of
<code>a</code> and there is a directory structure of:</p>
<ul>
<li><code>/Users/mjr/app/a.js</code></li>
<li><code>/Users/mjr/app/node_modules/b/b.js</code></li>
</ul>
<p>References to <code>__dirname</code> within <code>b.js</code> will return
<code>/Users/mjr/app/node_modules/b</code> while references to <code>__dirname</code> within <code>a.js</code>
will return <code>/Users/mjr/app</code>.</p>
<h2>__filename<span><a class="mark" href="#globals_filename" id="globals_filename">#</a></span></h2>
<!-- type=var -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;String&gt;</a></li>
</ul>
<p>The filename of the code being executed.  This is the resolved absolute path
of this code file.  For a main program this is not necessarily the same
filename used in the command line.  The value inside a module is the path
to that module file.</p>
<p>Example: running <code>node example.js</code> from <code>/Users/mjr</code></p>
<pre><code class="lang-js">console.log(__filename);
// /Users/mjr/example.js
</code></pre>
<p><code>__filename</code> isn&#39;t actually a global but rather local to each module.</p>
<h2>clearImmediate(immediateObject)<span><a class="mark" href="#globals_clearimmediate_immediateobject" id="globals_clearimmediate_immediateobject">#</a></span></h2>
<!--type=global-->
<p><a href="timers.html#timers_clearimmediate_immediateobject"><code>clearImmediate</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>clearInterval(intervalObject)<span><a class="mark" href="#globals_clearinterval_intervalobject" id="globals_clearinterval_intervalobject">#</a></span></h2>
<!--type=global-->
<p><a href="timers.html#timers_clearinterval_intervalobject"><code>clearInterval</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>clearTimeout(timeoutObject)<span><a class="mark" href="#globals_cleartimeout_timeoutobject" id="globals_cleartimeout_timeoutobject">#</a></span></h2>
<!--type=global-->
<p><a href="timers.html#timers_cleartimeout_timeoutobject"><code>clearTimeout</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>console<span><a class="mark" href="#globals_console" id="globals_console">#</a></span></h2>
<!-- type=global -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>Used to print to stdout and stderr. See the <a href="console.html"><code>console</code></a> section.</p>
<h2>exports<span><a class="mark" href="#globals_exports" id="globals_exports">#</a></span></h2>
<!-- type=var -->
<p>A reference to the <code>module.exports</code> that is shorter to type.
See <a href="modules.html">module system documentation</a> for details on when to use <code>exports</code> and
when to use <code>module.exports</code>.</p>
<p><code>exports</code> isn&#39;t actually a global but rather local to each module.</p>
<p>See the <a href="modules.html">module system documentation</a> for more information.</p>
<h2>global<span><a class="mark" href="#globals_global" id="globals_global">#</a></span></h2>
<!-- type=global -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> The global namespace object.</li>
</ul>
<p>In browsers, the top-level scope is the global scope. That means that in
browsers if you&#39;re in the global scope <code>var something</code> will define a global
variable. In Node.js this is different. The top-level scope is not the global
scope; <code>var something</code> inside an Node.js module will be local to that module.</p>
<h2>module<span><a class="mark" href="#globals_module" id="globals_module">#</a></span></h2>
<!-- type=var -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>A reference to the current module. In particular
<code>module.exports</code> is used for defining what a module exports and makes
available through <code>require()</code>.</p>
<p><code>module</code> isn&#39;t actually a global but rather local to each module.</p>
<p>See the <a href="modules.html">module system documentation</a> for more information.</p>
<h2>process<span><a class="mark" href="#globals_process" id="globals_process">#</a></span></h2>
<!-- type=global -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
<p>The process object. See the <a href="process.html#process_process"><code>process</code> object</a> section.</p>
<h2>require()<span><a class="mark" href="#globals_require" id="globals_require">#</a></span></h2>
<!-- type=var -->
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>To require modules. See the <a href="modules.html#modules_modules">Modules</a> section.  <code>require</code> isn&#39;t actually a
global but rather local to each module.</p>
<h3>require.cache<span><a class="mark" href="#globals_require_cache" id="globals_require_cache">#</a></span></h3>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
</div><p>Modules are cached in this object when they are required. By deleting a key
value from this object, the next <code>require</code> will reload the module. Note that
this does not apply to <a href="addons.html">native addons</a>, for which reloading will result in an
Error.</p>
<h3>require.extensions<span><a class="mark" href="#globals_require_extensions" id="globals_require_extensions">#</a></span></h3>
<pre class="api_stability api_stability_0">Stability: 0 - Deprecated</pre><div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
</ul>
</div><p>Instruct <code>require</code> on how to handle certain file extensions.</p>
<p>Process files with the extension <code>.sjs</code> as <code>.js</code>:</p>
<pre><code class="lang-js">require.extensions[&#39;.sjs&#39;] = require.extensions[&#39;.js&#39;];
</code></pre>
<p><strong>Deprecated</strong>  In the past, this list has been used to load
non-JavaScript modules into Node.js by compiling them on-demand.
However, in practice, there are much better ways to do this, such as
loading modules via some other Node.js program, or compiling them to
JavaScript ahead of time.</p>
<p>Since the Module system is locked, this feature will probably never go
away.  However, it may have subtle bugs and complexities that are best
left untouched.</p>
<h3>require.resolve()<span><a class="mark" href="#globals_require_resolve" id="globals_require_resolve">#</a></span></h3>
<p>Use the internal <code>require()</code> machinery to look up the location of a module,
but rather than loading the module, just return the resolved filename.</p>
<h2>setImmediate(callback[, arg][, ...])<span><a class="mark" href="#globals_setimmediate_callback_arg" id="globals_setimmediate_callback_arg">#</a></span></h2>
<!-- type=global -->
<p><a href="timers.html#timers_setimmediate_callback_arg"><code>setImmediate</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>setInterval(callback, delay[, arg][, ...])<span><a class="mark" href="#globals_setinterval_callback_delay_arg" id="globals_setinterval_callback_delay_arg">#</a></span></h2>
<!-- type=global -->
<p><a href="timers.html#timers_setinterval_callback_delay_arg"><code>setInterval</code></a> is described in the <a href="timers.html">timers</a> section.</p>
<h2>setTimeout(callback, delay[, arg][, ...])<span><a class="mark" href="#globals_settimeout_callback_delay_arg" id="globals_settimeout_callback_delay_arg">#</a></span></h2>
<!-- type=global -->
<p><a href="timers.html#timers_settimeout_callback_delay_arg"><code>setTimeout</code></a> is described in the <a href="timers.html">timers</a> section.</p>

      </div>
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
</body>
</html>

